<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class="app-container">
    <el-form id="mvcfm">
      <el-row>
        <el-col :span="7" :xs="24">
          <div class="form-unit">
            <span class="mvc-title-left"> 我的仪表盘 </span>
          </div>
          <div>
            <el-row>
              <el-col :span="24">
                <div style="display: flex;align-items: center;justify-content: center;">
                  <div id="all_chart" style="width:100%;height: 500px;"></div>
                </div>
              </el-col>
            </el-row>
          </div>
        </el-col>
        <el-col :span="16" :xs="24"> 采购状态 <el-select v-model="s_search.CMIDstate">
            <el-option label="全部" value="-1" />
            <el-option label="待采购" value="0" />
            <el-option label="采购中" value="1" />
            <el-option label="已完成" value="2" />
          </el-select> 产品名称 <div class="el-select">
            <el-input v-model="s_search.plan_product_name" />
          </div>
          <el-button @click="getPage(1);" type='primary' size="mini"><i class='fa fa-search'></i>搜索</el-button>
          <el-button @click="gotoPage('/psi/supplychainmana/IncreaseProcurement?'+vueparams+'')" type='success' size="mini"><i class='fa fa-plus'></i>增加采购</el-button>
          <div>
          </div>
          <div class="form-unit">
            <span class="mvc-title-left"> 计划列表 </span>
          </div>
          <el-table :data="pageList" v-loading="loading">
            <el-table-column label="操作" align="center" width='100' type=''>
              <template slot-scope="scope">
                <el-dropdown trigger="click">
                  <span class="el-dropdown-link">操作<i class="el-icon-arrow-down el-icon--right"></i></span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <el-link @click="d_plan('&CMIDplan_id='+scope.row.plan_id+'')">删除</el-link>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
            <el-table-column label="#" align="center" type='index'>
            </el-table-column>
            <el-table-column label="产品名称" prop="plan_id">
              <template slot-scope="scope">
                <el-link @click="gotoPage('/psi/supplychainmana/IncreaseProcurementDet?CMIDplan_id='+scope.row.plan_id+''+vueparams+'')" type='primary'>{{scope.row.product_name}}</el-link>
              </template>
            </el-table-column>
            <el-table-column label="规格" prop="product_norm">
            </el-table-column>
            <el-table-column label="型号" prop="product_model">
            </el-table-column>
            <el-table-column label="需求数量" prop="product_num">
            </el-table-column>
            <el-table-column label="发布时间" prop="release_time">
              <template slot-scope="scope">
                {{getDateTimeString(scope.row,'release_time')}}
              </template>
            </el-table-column>
            <el-table-column label="状态" prop="state">
              <template slot-scope="scope">
                {{getValueName("待采购=0,已采购=1",scope.row.state)}}
              </template>
            </el-table-column>
          </el-table>
          <pagination v-show="total>0" :total="total" :limit.sync="pageSize" @pagination="getPage" />
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
  import request from '@/utils/request'
  export default {
    name: 'PurchaseStatistical',
    components: {},
    props: ['popparams'],
    data() {
      return {
        vueparams: this.getVUEParams(""),
        s_search: {
          CMIDstate: null,
          plan_product_name: null,
        },
        s_plan: [],
        all: [],
        loading: true,
        pageList: [],
        pageSize: 10,
        total: null,
        rules: {}
      }
    },
    created() {
      this.getData();
      this.getPage(1);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/psi/supplychainmana/PurchaseStatisticalAction/purchaseStatistical?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
          this.initChart();
        })
      },
      d_plan(_params) {
        request({
          method: 'post',
          url: '/xcapi/VUEAction/psi/supplychainmana/PurchaseStatisticalAction/d_plan?' + _params + this.vueparams,
          data: this.postData()
        }).then(data => {
          this.$router.replace("/redirect" + this.$route.fullPath);
          this.msgSuccess(data.msg);
        })
      },
      getPage(page) {
        this.loading = true;
        request({
          method: 'get',
          url: '/xcapi/VUEAction/psi/supplychainmana/PurchaseStatisticalAction/s_plan?' + this.vueparams,
          params: {
            pageNo: page
          }
        }).then(data => {
          this.loading = false;
          this.pageList = data.rows;
          this.total = data.total;
        })
      },
      initChart() {
        var all_config = {
          legend: {
            data: getDataSet(this.all, "series")
          },
          tooltip: {},
          toolbox: {
            show: true,
            orient: 'vertical',
            left: 'right',
            top: 'center',
            feature: {
              mark: {
                show: true
              },
              dataView: {
                show: true,
                readOnly: false
              },
              magicType: {
                show: true,
                type: ['line', 'bar', 'stack', 'tiled']
              },
              restore: {
                show: true
              },
              saveAsImage: {
                show: true
              }
            }
          },
          series: [{
            type: "pie",
            data: getDataSeries(this.all),
            center: ["50%", "60%"], //圆心坐标
            radius: "55%" //远的半径
          }],
        };
        var myChart = this.initchart(document.getElementById('all_chart'));
        myChart.setOption(all_config);
      },
    },
  }
</script>
